﻿namespace EasyWeb
{
    using System;
    using System.Globalization;

    [Serializable]
    public class EWCultureInfo
    {
        private readonly Guid id;
        private readonly string name;
        private readonly bool enabled;
        [NonSerialized]
        private CultureInfo culture;

        // for serialization support
        private EWCultureInfo()
        {
        }

        public EWCultureInfo(Guid id, string name, bool enabled)
        {
            this.id = id;
            this.name = name;
            this.culture = CultureInfo.GetCultureInfo(name);
            this.enabled = enabled;
        }

        public Guid Id
        {
            get { return this.id; }
        }

        public CultureInfo Culture
        {
            get
            {
                // if the current instance is created via the default ctor, the field culture is null
                if (this.culture == null)
                {
                    this.culture = CultureInfo.GetCultureInfo(name);
                }

                return this.culture;
            }
        }

        public bool Enabled
        {
            get { return this.enabled; }
        }
    }
}
